<template>
  <!-- 收货启动,记录卸货人 -->
		<div class="ywshouhuo_xhr">

			<van-nav-bar :fixed="true" class="navBar" title="收货启动新" left-arrow @click-left="$router.go(-1)"></van-nav-bar>

				<div class="goodsFromWarp">
						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">预检单号：</div>
								</div>



								<van-field
									 clearable
									 class="skuInput"
									 v-model="editForm.bill"
									 placeholder="请填写入库标签"
									 @keyup="onEnter($event,do_inputspbar)"
								 />

								<div class="searchBtn">
									<button :disabled="isdisabled"  @click.stop="searchGoodsBtn()" >
										<van-icon name="ellipsis" color="#1989fa"  />
									</button>
								</div>
						</div>


						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">供应商：</div>
								</div>
								<div class="skuNoInput">
									{{editForm.message}}
								</div>
						</div>
				</div>



				<div class="goodsFromWarp">
						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">卸货人1：</div>
								</div>
								<van-field
									 style="width:100%;"
									 clearable
									 class="skuInput"
									 v-model="editForm.xhr1"
									 placeholder="卸货人1"
								 />
								 <div class="xiehuoren">{{editForm.xhr1Name}}</div>

								<div class="searchBtn">
										<button :disabled="isdisabled"  @click.stop="saveShangJiaBtn(editForm.xhr1)" >
											<van-icon name="search" size="20" color="#1989fa"  />
										</button>
								 </div>
						</div>

						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">卸货人2：</div>
								</div>
								<van-field
									  style="width:100%;"
									 clearable
									 class="skuInput"
									 v-model="editForm.xhr2"
									 placeholder="卸货人2"
								 />
								<div class="xiehuoren">{{editForm.xhr2Name}}</div>

								<div class="searchBtn">
										<button :disabled="isdisabled"  @click.stop="saveShangJiaBtn(editForm.xhr2)" >
												<van-icon name="search" size="20" color="#1989fa"  />
										</button>
								 </div>
						</div>

						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">卸货人3：</div>
								</div>
								<van-field
									 style="width:100%;"
									 clearable
									 class="skuInput"
									 v-model="editForm.xhr3"
									 placeholder="卸货人3"
								 />
								  <div class="xiehuoren">{{editForm.xhr3Name}}</div>

									<div class="searchBtn">
											<button :disabled="isdisabled"  @click.stop="saveShangJiaBtn(editForm.xhr3)" >
													<van-icon name="search" size="20" color="#1989fa"  />
											</button>
									 </div>
						</div>

						<div class="goodsInputWarp">
								<div class="goodsInputLabel">
									<div class="goodsInputBorder"></div>
									<div class="skuName">卸货人4：</div>
								</div>
								<van-field
								   style="width:100%;"
									 clearable
									 class="skuInput"
									 v-model="editForm.xhr4"
									 placeholder="卸货人4"
								 />
								  <div class="xiehuoren">{{editForm.xhr4Name}}</div>

									<div class="searchBtn">
											<button :disabled="isdisabled"  @click.stop="saveShangJiaBtn(editForm.xhr4)" >
													<van-icon name="search" size="20" color="#1989fa"  />
											</button>
									 </div>
						</div>
				</div>


				<van-overlay :show="isSkuVisible" :lock-scroll="false">
					<div class="shipandanWrapper">
							<van-sticky>
								<van-nav-bar class="navBar" title="商品列表" left-arrow @click-left="isSkuVisible = false"></van-nav-bar>
							</van-sticky>
							<div class="shipandanCon" @click.stop>
									<div  v-for="(row,i) in tableData" :key="i" class="danjuRow" @click="selectSkuClick(row)" >
										<van-row class="skuList">
										  <van-col span="24"> <span>单据类型：</span> {{fmartStatus(row.djtype)}}</van-col>
										</van-row>
											<!-- SH收货单 DBSH调拨收货单PSFC配送返仓单 -->
										<van-row class="skuList" >
										  <van-col span="24"> <span>单号：</span> {{row.bill}}</van-col>
										</van-row>

										<van-row class="skuList"  >
											<van-col span="24"> <span>供应商：</span> {{row.vendor}}</van-col>
										</van-row>

										<van-row class="skuList"  >
											<van-col span="24"> <span>门店：</span> {{row.storeid}}</van-col>
										</van-row>

										<van-row class="skuList"  >
											<van-col span="24"> <span>仓别：</span> {{row.cb}}</van-col>
										</van-row>
										<van-row class="skuList"  >
											<van-col span="24"> <span>库位：</span> {{row.posin}}</van-col>
										</van-row>


									</div>
							</div>
					</div>
				</van-overlay>











				<div class="skuBtn" style="justify-content: flex-end;">
					<van-button type="info" :disabled="isdisabled" @click="baocunClick()">保存</van-button>
				</div>
		</div>

</template>

<script>
import { mapActions } from "vuex";
export default {
  name: 'shouhuoqidongnews',
  data () {
    return {
			editForm:{
				bill:'', //预检单号
				djtype:'',
				message:'',
				xhr1:'',
				xhr1Name:'',
				xhr2:'',
				xhr2Name:'',
				xhr3:'',
				xhr3Name:'',
				xhr4:'',
				xhr4Name:'',
			},
			isdisabled:false,
			isSkuVisible:false,
			tableData:[],
    }
  },
  methods: {
		 ...mapActions(["showLoading", "hideLoading"]),
		 fmartStatus(djtype){
				if(djtype == 'SH'){
					return '收货单'
				}else if(djtype == 'DBSH'){
					return '调拨收货单'
				}else if(djtype == 'PSFC'){
					return '配送返仓单'
				}
		 },
		do_inputspbar(pmtxt){
			console.log(pmtxt)  //扫描枪获取的参数
			this.editForm.bill = pmtxt
			this.searchGoodsBtn()
		},
		 searchGoodsBtn(){
			 console.log(this.editForm)
			 var _self = this;
			 var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			 this.MYPOST({
				'method':'dgate',
				'pname':'f_wmsa_y_shouhuo',
				'i':this.FNULLE([
					'opmode','Y_SHQD_qrybill',
					'kqid', this.ryuser.kqid,
					'czyid',this.ryuser.operatorid,
					'bill',this.editForm.bill,
				])
				}, '预检单号查询',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
				if(ret_iserr){ //传入的true参数,理论上不会有此回调了
					_self.$toast.fail('查询失败')
					_self.$store.commit('hideLoading');
				}else{
					var rtn_json_obj = null;
					_self.$store.commit('hideLoading');
					if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
					}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
					}
					console.log("得到预检单号查询")
					console.log(rtn_json_obj)
					if(rtn_json_obj.length > 0){
						_self.tableData = rtn_json_obj
						_self.isSkuVisible = true
					}else{
						_self.$toast.fail('暂无预检单')
					}
				}
			 });
		 },
		 selectSkuClick(row){
			 this.editForm.bill = row.bill
			 this.editForm.djtype = row.djtype
			 this.isSkuVisible = false
			 this._getSkuClick()
			 this._getXHR()
		 },
		 _getSkuClick(){
			 console.log(this.editForm)
			 console.log(this.ryuser)
			 var _self = this;
			 var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			 this.MYPOST({
					'method':'dgate',
					'pname':'f_wmsa_y_shouhuo',
					'i':this.FNULLE([
						'opmode','Y_SHQD_jybill',
						'kqid', this.ryuser.kqid,
						'czyid',this.ryuser.operatorid,
						'djtype',this.editForm.djtype,
						'bill',this.editForm.bill,
					])
					}, '单据信息',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
					if(ret_iserr){ //传入的true参数,理论上不会有此回调了
						_self.$toast.fail('查询失败')
						_self.$store.commit('hideLoading');
					}else{
						var rtn_json_obj = null;
						_self.$store.commit('hideLoading');
						if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
						}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
						}

						console.log("单据信息")
						console.log(rtn_json_obj)
						if(rtn_json_obj[0].ret_ret == '0'){
							_self.editForm.message = rtn_json_obj[0].ret_mess
						}else{
							_self.$toast(rtn_json_obj[0].ret_mess)
						}
						_self.isSkuVisible = false
					}
			 });
		 },
		 _getXHR(){
			 var _self = this;
			 var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			 this.MYPOST({
					'method':'dgate',
					'pname':'f_wmsa_y_shouhuo',
					'i':this.FNULLE([
						'opmode','Y_SHQD_qryxhr',
						'kqid', this.ryuser.kqid,
						'czyid',this.ryuser.operatorid,
						'djtype',this.editForm.djtype,
						'bill',this.editForm.bill,
					])
					}, '卸货人',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
					if(ret_iserr){ //传入的true参数,理论上不会有此回调了
						_self.$toast.fail('查询失败')
						_self.$store.commit('hideLoading');
					}else{
						var rtn_json_obj = null;
						_self.$store.commit('hideLoading');
						if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
						}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
						}

						console.log("得到卸货人")
						console.log(rtn_json_obj)
						if(rtn_json_obj.length == 1){
							_self.editForm.xhr1 = 		rtn_json_obj[0].zyryid
							_self.editForm.xhr1Name = rtn_json_obj[0].opername
						}else if(rtn_json_obj.length == 2){
							_self.editForm.xhr1 = 		rtn_json_obj[0].zyryid
							_self.editForm.xhr1Name = rtn_json_obj[0].opername
							_self.editForm.xhr2 = 		rtn_json_obj[1].zyryid
							_self.editForm.xhr2Name = rtn_json_obj[1].opername
						}else if(rtn_json_obj.length == 3){
							_self.editForm.xhr1 = rtn_json_obj[0].zyryid
							_self.editForm.xhr1Name = rtn_json_obj[0].opername
							_self.editForm.xhr2 = rtn_json_obj[1].zyryid
							_self.editForm.xhr2Name = rtn_json_obj[1].opername
							_self.editForm.xhr3 = rtn_json_obj[2].zyryid
							_self.editForm.xhr3Name = rtn_json_obj[2].opername
						}else if(rtn_json_obj.length == 4){
							_self.editForm.xhr1 =			rtn_json_obj[0].zyryid
							_self.editForm.xhr1Name = rtn_json_obj[0].opername
							_self.editForm.xhr2 = 		rtn_json_obj[1].zyryid
							_self.editForm.xhr2Name = rtn_json_obj[1].opername
							_self.editForm.xhr3 = 		rtn_json_obj[2].zyryid
							_self.editForm.xhr3Name = rtn_json_obj[2].opername
							_self.editForm.xhr4 = 		rtn_json_obj[3].zyryid
							_self.editForm.xhr4Name = rtn_json_obj[3].opername
						}
					}
			 });
		 },
		 saveShangJiaBtn(xhr){
				var _self = this;
				var ldemodata = [{retval:0, errmsg:'返回数据集'},]
				this.MYPOST({
						'method':'dgate',
						'pname':'f_wmsa_y_shouhuo',
						'i':this.FNULLE([
							'opmode','Y_SHQD_qryczy',
							'kqid', this.ryuser.kqid,
							'czyid',this.ryuser.operatorid,
							'djtype',this.editForm.djtype,
							'xhr',xhr,
						])
						}, '查询单条卸货人',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
						if(ret_iserr){ //传入的true参数,理论上不会有此回调了
							_self.$toast.fail('查询失败')
							_self.$store.commit('hideLoading');
						}else{
							var rtn_json_obj = null;
							_self.$store.commit('hideLoading');
							if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
							}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
							}

							console.log("查询单条卸货人")
							console.log(rtn_json_obj)
						}
				});
		 },
		 baocunClick(){
			 var _self = this;
			 var ldemodata = [{retval:0, errmsg:'返回数据集'},]
			 this.MYPOST({
			 		'method':'dgate',
			 		'pname':'f_wmsa_y_shouhuo',
			 		'i':this.FNULLE([
			 			'opmode','Y_SHQD_savexhr',
			 			'kqid', this.ryuser.kqid,
			 			'czyid',this.ryuser.operatorid,
			 			'djtype',this.editForm.djtype,
			 			'bill',this.editForm.bill,
			 			'xh1',this.editForm.xhr1,
			 			'xh2',this.editForm.xhr2,
			 			'xh3',this.editForm.xhr3,
			 			'xh4',this.editForm.xhr4,
			 		])
			 		}, '保存卸货人',true, ldemodata, function(ret_obj, ret_iserr,ret_errmess,ret_oldresp){
			 		if(ret_iserr){ //传入的true参数,理论上不会有此回调了
			 			_self.$toast.fail('查询失败')
			 			_self.$store.commit('hideLoading');
			 		}else{
			 			var rtn_json_obj = null;
			 			_self.$store.commit('hideLoading');
			 			if(ret_obj != null){ rtn_json_obj = ret_obj; //返回的接口可以直接解析的情况
			 			}else{  rtn_json_obj = _self.arr2Obj(ret_oldresp.data); //非标准的dgate接口,返回的一个不兼容的处理
			 			}

			 			console.log("查询保存卸货人")
			 			console.log(rtn_json_obj)
						if(rtn_json_obj[0].ret_ret == '-1'){
							_self.$toast.fail(rtn_json_obj[0].ret_mess)
							return
						}else{
							_self.$toast.fail(rtn_json_obj[0].ret_mess)

							_self.editForm.xhr1 		=	''
							_self.editForm.xhr1Name = ''
							_self.editForm.xhr2 		= ''
							_self.editForm.xhr2Name = ''
							_self.editForm.xhr3 		= ''
							_self.editForm.xhr3Name = ''
							_self.editForm.xhr4 		= ''
							_self.editForm.xhr4Name = ''
							_self.editForm.bill = ''
							_self.editForm.message = ''
						}
			 		}
			 });
		 },
  },
  components:{

  },
  computed: {
     ryuser: function(){
       return this.GWO(true).gUSER;
     }
  },
  mounted :function(){
    var _self = this; window.GWO().debug=this;
  }
}

</script>
<style scoped lang="scss">
// 引入公共样式
@import '@/assets/css/base.scss';
@import '@/assets/css/input.scss';
.ywshouhuo_xhr{
	padding-top:50px;
	padding-bottom: 50px;
}
.xiehuoren{
	width:100px;
	font-size: 12px;
	margin-left: 10px;
}
</style>

